// pages/map/map.js
import points from '../../assets/json/points';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    
    enable3d: false,
    showLocation: true,
    showCompass: false,
    enableOverlooking: false,
    enableZoom: true,
    enableScroll: true,
    enableRotate: false,
    drawPolygon: false,
    enableSatellite: false,
    enableTraffic: false,
    latitude: '30.873496',
    longitude: '120.131063',
    scale: 16,
    markers: [],
    circles: [],
    polylines: [],
    polygons: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const app = getApp();
    wx.showLoading({
      title: '加载中',
      mask: true
    });
    wx.request({
      url: app.globalData.api + '/points/',
      method: 'GET',
      success: (result) => {
        wx.hideLoading();
        const markers = result.data.map(point => {
          return {
            id: point.fid,
            latitude: point.geometry.coordinates[1],
            longitude: point.geometry.coordinates[0],
            width: '24px',
            height: '24px',
            iconPath: '../../assets/images/location.png',
            label: {
              content: point.name
            }
          };
        });
        this.setData({
          markers: markers
        });
      }
    })
    // const markers = points.map(point => {
    //   return {
    //     id: point.fid,
    //     latitude: point.geometry.coordinates[1],
    //     longitude: point.geometry.coordinates[0],
    //     iconPath: '../../assets/images/location.png',
    //     width: '24px',
    //     height: '24px',
    //     label: {
    //       content: point.name
    //     }
    //   };
    // });
    // this.setData({
    //   markers: markers
    // });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})